#include "PayOffFactory.h"

PayOffFactory& PayOffFactory::Instance()
{
	static PayOffFactory payoffFactory;
	return payoffFactory;
}

void PayOffFactory::registerPayOff(std::string payoff_id, CreatePayOff payoff_creator)
{
	m_payoffs.insert(std::pair<std::string,CreatePayOff>(payoff_id,payoff_creator));
}

PayOff* PayOffFactory::createPayOff(std::string payoff_id, double strike)
{
	std::map<std::string, CreatePayOff>::const_iterator iter;
	iter = m_payoffs.find(payoff_id);
	if(iter!=m_payoffs.end()){
		return iter->second(strike);
	}
	else{
		return 0;
	}
}

std::vector<std::string> PayOffFactory::getAllPayOffs() const
{
	std::vector<std::string> payoffs_id;
	std::map<std::string, CreatePayOff>::const_iterator iter;
	for(iter=m_payoffs.begin(); iter!=m_payoffs.end(); ++iter) {
		payoffs_id.push_back(iter->first);
	}
	return payoffs_id;
}